package com.zhiyou100.emtity;

import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: 马跃
 * @create: 2021-01-21 18:55
 **/
public class PageModel<T> {

    private int currentPage;// 当前页
    private int beginPage;// 起始页
    private int endPage;// 结束页
    private int totalPage;// 总页码数
    private int pageNum;// 页码数
    private List<T> list;

    public void caluBeginAndEnd() {
        if (currentPage + pageNum / 2 > totalPage) {
            endPage = totalPage;
            beginPage = (endPage - pageNum) < 1 ? 1 : endPage - (pageNum - 1);
        } else {
            beginPage = (currentPage + pageNum / 2) < 1 ? 1 : currentPage - (pageNum - 1) / 2;
            endPage = beginPage + (pageNum - 1) > totalPage ? totalPage : beginPage + (pageNum - 1);
        }
    }

    public PageModel(int currentPage, int totalPage, int pageNum, List<T> list) {
        this.currentPage = currentPage;
        this.totalPage = totalPage;
        this.pageNum = pageNum;
        this.list = list;
        caluBeginAndEnd();
    }

    public PageModel() {
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public int getBeginPage() {
        return beginPage;
    }

    public void setBeginPage(int beginPage) {
        this.beginPage = beginPage;
    }

    public int getEndPage() {
        return endPage;
    }

    public void setEndPage(int endPage) {
        this.endPage = endPage;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public List<?> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    @Override
    public String toString() {
        return "PageModel{" +
                "currentPage=" + currentPage +
                ", beginPage=" + beginPage +
                ", endPage=" + endPage +
                ", totalPage=" + totalPage +
                ", pageNum=" + pageNum +
                ", list=" + list +
                '}';
    }
}
